﻿using DevExpress.XtraEditors;
using DXApplicationTangche.service;
using DXApplicationTangche.UC.圣同润.Service;
using DXApplicationTangche.UC.圣同润.UC;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DXApplicationTangche.UC.圣同润
{
    public partial class Form商品分类一览 : DevExpress.XtraEditors.XtraForm
    {
        private ProductIndexDTO productIndexDTO = new ProductIndexDTO();
        public Form商品分类一览(String category)
        {
            InitializeComponent();
            this.getData(category);
        }
        private void getData(String category)
        {
            this.productIndexDTO = 圣同润Service.getProductIndexAll(category);
            for (int i = 0; i < this.productIndexDTO.productIndexMetaElementDTOS.Count; i++)
            {
                int index = i + 1;
                this.gridView商品分类一览.Columns.ColumnByName("gridColumn" + index).Caption
                    = productIndexDTO.productIndexMetaElementDTOS[i].caption;
                this.gridView商品分类一览.Columns.ColumnByName("gridColumn" + index).Visible
                    = productIndexDTO.productIndexMetaElementDTOS[i].visible;
                this.gridView商品分类一览.Columns.ColumnByName("gridColumn" + index).FieldName
                    = productIndexDTO.productIndexMetaElementDTOS[i].fieldName;
            }
            this.gridControl商品分类一览.DataSource = this.productIndexDTO.viewChanmamaProductClassInfoDaos;
            this.gridView商品分类一览.RefreshData();
        }

        private void rowData(ViewChanmamaProductClassInfoDao viewChanmamaProductClassInfoDao)
        {
            this.textBox昨日销量.Text = viewChanmamaProductClassInfoDao.yesterdaySales;
            this.textBox昨日浏览.Text = viewChanmamaProductClassInfoDao.yesterdayBrowses;
            this.textBox店名.Text = viewChanmamaProductClassInfoDao.shopNameCn;
            this.textBox品牌名.Text = viewChanmamaProductClassInfoDao.brandName;
            //this.textBox商品一级分类.Text = viewChanmamaProductClassInfoDao.first_cname;
            //this.textBox商品二级分类.Text = viewChanmamaProductClassInfoDao.second_cname;
            //this.textBox商品三级分类.Text = viewChanmamaProductClassInfoDao.third_cname;
            this.textBox商品名.Text = viewChanmamaProductClassInfoDao.title;
            this.textBox三十日销量.Text = viewChanmamaProductClassInfoDao.pvCount;
            this.textBox评论总数.Text = viewChanmamaProductClassInfoDao.commentQuantity;
            this.textBox抖音总转化率.Text = viewChanmamaProductClassInfoDao.douyinConversionRate;
            this.textBox月转化率.Text = viewChanmamaProductClassInfoDao.monthConversionRate;
            this.textBox月直播总场次.Text = viewChanmamaProductClassInfoDao.monthLiveRoomCount;
            this.textBox市场价.Text = viewChanmamaProductClassInfoDao.marketPrice;
            this.textBox最高价.Text = viewChanmamaProductClassInfoDao.maxPrice;
            this.textBox零售价.Text = viewChanmamaProductClassInfoDao.salesPrice;
            this.textBox最终价.Text = viewChanmamaProductClassInfoDao.finalPrice;
            this.textBox历史最低价.Text = viewChanmamaProductClassInfoDao.lowestPrice;
            this.textBox佣金.Text = viewChanmamaProductClassInfoDao.commission;
            this.textBox店铺评分.Text = viewChanmamaProductClassInfoDao.shopExprScore;
            this.textBox总销量.Text = viewChanmamaProductClassInfoDao.sales;
            this.textBox热推达人.Text = viewChanmamaProductClassInfoDao.nickname;
            this.hyperLinkEdit抖音链接.Text = viewChanmamaProductClassInfoDao.url;
            try
            {
                this.pictureBox头图.Image = FileService.GetImageByUrl(viewChanmamaProductClassInfoDao.imageUrl);
            }
            catch { }
        }

        private void gridView商品分类一览_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)
        {
            try
            {
                String productId = this.gridView商品分类一览.GetRowCellValue(this.gridView商品分类一览.FocusedRowHandle, "productId").ToString();
                foreach (ViewChanmamaProductClassInfoDao item in this.productIndexDTO.viewChanmamaProductClassInfoDaos)
                {
                    if (productId.Equals(item.productId))
                    {
                        this.rowData(item);
                        break;
                    }
                }
            }
            catch { }
        }

        private void 查看详情ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                String productId = this.gridView商品分类一览.GetRowCellValue(this.gridView商品分类一览.FocusedRowHandle, "productId").ToString();
                new Form商品信息(productId).ShowDialog();
            }
            catch { }
        }
    }
}